<template>
  <el-dialog v-model="relevancyStaffDialog" title="关联角色" width="500">
    <el-form>
      <div class="mt-4">
        <el-checkbox-group v-model="props.formData.roleNameList">
          <el-checkbox
            v-for="(item, index) in props.roleNameList"
            :key="index"
            :value="item.roleId"
            :label="item.roleName"
            border
          />
        </el-checkbox-group>
      </div>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="relevancyStaffDialog = false">取消</el-button>
        <el-button type="primary" @click="update" :disabled="isDisable">
          保存
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
  
  <script setup>
import axios from "@/axios/index";
import { ElMessage } from "element-plus";
import { ref } from "vue";

let props = defineProps(["roleNameList", "currentID", "formData"]);

let relevancyStaffDialog = defineModel("relevancyStaffDialog");
//避免重复点击
let isDisable = ref(false);

//提交修改角色
function update() {
  isDisable.value = true;
  //修改角色
  axios
    .put("/staffRole/updateStaffRole", null, {
      params: {
        roleId: props.currentID,
        roleNameList: props.formData.roleNameList.join(","),
      },
    })
    .then((resp) => {
      relevancyStaffDialog.value = false;
      isDisable.value = false;
      
      
      ElMessage({
        message: resp.data.message,
        type: "success",
        duration: 1000,
      });
    });
}
</script>
  
  <style scoped>
.avatar-uploader .avatar {
  width: 50px;
  height: 50px;
  display: block;
}
</style>
  
  <style>
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 70px;
  height: 70px;
  text-align: center;
}
</style>